package com.level.system.base;

import java.io.Serializable;

public class ResponseBean<T> implements Serializable {
    private static final long serialVersionUID = 1894648231137314539L;
    private int code;
    private String msg;
    private T data;
    private static final int FAIL_CODE = 500;
    private static final int SUCCUSS_CODE = 200;

    public ResponseBean() {
    }

    public static <T> ResponseBean<T> success() {
    	ResponseBean<T> ajaxResult = new ResponseBean<T>();
        ajaxResult.setCode(SUCCUSS_CODE);
        ajaxResult.setMsg((String)null);
        ajaxResult.setData((T)null);
        return ajaxResult;
    }

    public static <T> ResponseBean<T> success(String message, T object) {
    	ResponseBean<T> ajaxResult = new ResponseBean<T>();
        ajaxResult.setCode(SUCCUSS_CODE);
        ajaxResult.setMsg(message);
        ajaxResult.setData(object);
        return ajaxResult;
    }

    public static <T> ResponseBean<T> success(T object) {
    	ResponseBean<T> ajaxResult = new ResponseBean<T>();
        ajaxResult.setCode(SUCCUSS_CODE);
        ajaxResult.setMsg("");
        ajaxResult.setData(object);
        return ajaxResult;
    }

    public static <T> ResponseBean<T> success(String message) {
    	ResponseBean<T> ajaxResult = new ResponseBean<T>();
        ajaxResult.setCode(SUCCUSS_CODE);
        ajaxResult.setMsg(message);
        return ajaxResult;
    }

    public static <T> ResponseBean<T> fail(String message, T object) {
    	ResponseBean<T> ajaxResult = new ResponseBean<T>();
        ajaxResult.setCode(FAIL_CODE);
        ajaxResult.setMsg(message);
        ajaxResult.setData(object);
        return ajaxResult;
    }

    public static <T> ResponseBean<T> failForInvalidToken(String message) {
    	ResponseBean<T> ajaxResult = new ResponseBean<T>();
        ajaxResult.setCode(FAIL_CODE);
        ajaxResult.setMsg(message);
        return ajaxResult;
    }

    public static <T> ResponseBean<T> fail(String message) {
    	ResponseBean<T> ajaxResult = new ResponseBean<T>();
        ajaxResult.setCode(FAIL_CODE);
        ajaxResult.setMsg(message);
        return ajaxResult;
    }

    public static <T> ResponseBean<T> fail(int code, String message, T object) {
    	ResponseBean<T> ajaxResult = new ResponseBean<T>();
        ajaxResult.setCode(code);
        ajaxResult.setMsg(message);
        ajaxResult.setData(object);
        return ajaxResult;
    }

    public static <T> ResponseBean<T> fail(int code, T object) {
    	ResponseBean<T> ajaxResult = new ResponseBean<T>();
        ajaxResult.setCode(code);
        ajaxResult.setMsg((String)null);
        ajaxResult.setData(object);
        return ajaxResult;
    }

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String toString() {
        return "AjaxResult{code=" + this.code + ", msg='" + this.msg + '\'' + ", data=" + this.data + '}';
    }
}
